#define _CRT_SECURE_NO_WARNINGS 1
#include"sort.h"

void testInsertSort()
{
	int a[] = { 4,9,8,3,6,5,7,2,1 };
	int n = sizeof(a) / sizeof(a[0]);
	InsertSort(a, n);
	printf("InserSort:");
	printSort(a, n);
}

void testHeapSort()
{
	int a[] = { 4,9,8,3,6,5,7,2,1 };
	int n = sizeof(a) / sizeof(a[0]);
	HeapSort(a, n);
	printf("HeapSort:");
	printSort(a, n);
}

void testShellSort()
{
	int a[] = { 4,9,8,3,6,5,7,2,1 };
	int n = sizeof(a) / sizeof(a[0]);
	ShellSort(a, n);
	printf("ShelSort:");
	printSort(a, n);
}

void CompareSort()
{
	srand((unsigned)time(0));
	 const int n = 1000000;
	
	int* a1 = (int*)malloc(sizeof(int) * n);
	int* a2 = (int*)malloc(sizeof(int) * n);
	int* a3 = (int*)malloc(sizeof(int) * n);
	int* a4 = (int*)malloc(sizeof(int) * n);
	int* a5 = (int*)malloc(sizeof(int) * n);
	int* a6 = (int*)malloc(sizeof(int) * n);
	int* a7 = (int*)malloc(sizeof(int) * n);
	int* a8 = (int*)malloc(sizeof(int) * n);
	int* a9 = (int*)malloc(sizeof(int) * n);
	int* a10 = (int*)malloc(sizeof(int) * n);
	for (int i = 0; i < n; i++)
	{
		a1[i] = rand() + i;
		a2[i] = a1[i];
		a3[i] = a1[i];
		a4[i] = a1[i];
		a5[i] = a1[i];
		a6[i] = a1[i];
		a7[i] = a1[i];
		a8[i] = a1[i];
		a9[i] = a1[i];
		a10[i] = a1[i];
	}
	
	int begin1 = clock();
	//InsertSort(a1,n);
	int end1 = clock();
	printf("InsertSort:%dms\n", end1-begin1);
	
	int begin2 = clock();
	HeapSort(a2, n);
	int end2 = clock();
	printf("HeapSort:%dms\n", end2-begin2);

	int begin3 = clock();
	ShellSort(a3, n);
	int end3 = clock();
	printf("ShellSort:%dms\n", end3-begin3);

	int begin4 = clock();
	//BubbleSort(a4, n);
	int end4 = clock();
	printf("BubbleSort:%dms\n", end4 - begin4);

	int begin5 = clock();
	//SelectionSort(a5, n);
	int end5 = clock();
	printf("SelectionSort:%dms\n", end5 - begin5);

	int begin6 = clock();
	QuickSort(a6,0,n-1);
	int end6 = clock();
	printf("QuickSort:%dms\n", end6 - begin6);

	int begin7 = clock();
	QuickSortNonR(a7, 0, n - 1);
	int end7 = clock();
	printf("QuickSortNonR:%dms\n", end7 - begin7);

	int begin8 = clock();
	QuickSortinit(a8, 0, n - 1);
	int end8 = clock();
	printf("QuickSortinit:%dms\n", end8 - begin8);

	int begin9 = clock();
	MegerSort(a9,n);
	int end9 = clock();
	printf("MegerSort:%dms\n", end9 - begin9);

	int begin10 = clock();
	CountSort(a10, n);
	int end10 = clock();
	printf("CountSort:%dms\n", end10 - begin10);

	free(a1);
	free(a2);
	free(a3);
	free(a4);
	free(a5);
	free(a6);
	free(a7);
	free(a8);
	free(a9);
	free(a10);
}

void testBubbleSort()
{
	int a[] = { 4,9,8,3,6,5,7,2,1 };
	int n = sizeof(a) / sizeof(a[0]);
	BubbleSort(a, n);
	printf("BubbleSort:");
	printSort(a, n);
}

void testSelectionSort()
{
	//int a[] = { 4,9,8,3,6,5,7,2,1 };
	int a[] = { 9,1,2,5,7,4,6,3 };
	int n = sizeof(a) / sizeof(a[0]);
    SelectionSort(a, n);
	printf("SelectionSort:");
	printSort(a, n);
}

void testQuickSort()
{
	int a[] = { 4,9,8,3,6,5,7,2,1 };
	int n = sizeof(a) / sizeof(a[0]);
	QuickSort(a, 0,n-1);
	printf("QuickSort:");
	printSort(a, n);
}

void testQuickSortNonR()
{
	int a[] = { 4,9,8,3,6,5,7,2,1 };
	int n = sizeof(a) / sizeof(a[0]);
	QuickSortNonR(a, 0, n - 1);
	printf("QuickSortNonR:");
	printSort(a, n);
}

void testMegerSort()
{
	int a[] = { 10,6,7,1,3,9,4,2 };
	int n = sizeof(a )/ sizeof(a[0]);
	MegerSort(a, n);
	printf("MegerSort:");
	printSort(a, n);
}

void  testMegerSortNonR()
{
	//int a[] = { 10,6,7,1,3,9,4,2 };
	int a[] = { 10,6,7,1,3,9,4 };
	int n = sizeof(a) / sizeof(a[0]);
	MegerSortNonR(a, n);
	printf("MegerSortNonr:");
	printSort(a, n);
}

void testCountSort()
{
	int a[] = { 10,6,7,1,3,9,4,2 };
	int n = sizeof(a) / sizeof(a[0]);
	CountSort(a, n);
	printf("CountSort:");
	printSort(a, n);
}
int main()
{
	//testInsertSort();
	//testHeapSort();
	//testShellSort();
	//testBubbleSort();
	//testSelectionSort();
	//testQuickSort();
	//testQuickSortNonR();
	//testMegerSort();
	//testMegerSortNonR();
	//testCountSort();
	CompareSort();
	
	return 0;
}
